import logging
import allure
from core.keywords import Keywords

class AssertKeywords(Keywords):
    def assert_url(self, step):
        with allure.step(f"第{step['step_num']}步：{step['step_name']}"):
            logging.info(f"第{step['step_num']}步：{step['step_name']}--元素位置（{step['by']},{step['value']}）--数据{step['data']}--组元素索引{step['index']}")
            expected_url = step["data"]
            actual_url = self.driver.current_url
            assert actual_url == expected_url
    def assert_title(self, step):
        with allure.step(f"第{step['step_num']}步：{step['step_name']}"):
            logging.info(f"第{step['step_num']}步：{step['step_name']}--元素位置（{step['by']},{step['value']}）--数据{step['data']}--组元素索引{step['index']}")
            expected_title = step["data"]
            actual_title = self.driver.title
            assert actual_title == expected_title
    def assert_text(self, step):
        with allure.step(f"第{step['step_num']}步：{step['step_name']}"):
            logging.info(f"第{step['step_num']}步：{step['step_name']}--元素位置（{step['by']},{step['value']}）--数据{step['data']}--组元素索引{step['index']}")
            expected_text = step["data"]
            actual_text = self.find(step).text
            assert actual_text == expected_text

    def assert_alert_text(self, step):
        with allure.step(f"第{step['step_num']}步：{step['step_name']}"):
            logging.info(f"第{step['step_num']}步：{step['step_name']}--元素位置（{step['by']},{step['value']}）--数据{step['data']}--组元素索引{step['index']}")
            expected_alert_text = step["data"]
            actual_alert_text = self.driver.switch_to.alert.text
            assert actual_alert_text == expected_alert_text

    def assert_element_exists(self, step):
        with allure.step(f"第{step['step_num']}步：{step['step_name']}"):
            logging.info(f"第{step['step_num']}步：{step['step_name']}--元素位置（{step['by']},{step['value']}）--数据{step['data']}--组元素索引{step['index']}")
            assert self.find(step)